package com.young.springdemo.controller;

import com.young.springdemo.config.annotation.LogOperateType;
import com.young.springdemo.config.log.OperateLog;
import com.young.springdemo.controller.param.UserBase;
import com.young.springdemo.jpa.entity.TeacherEntity;
import com.young.springdemo.service.jpa.TeacherService;
import com.young.springdemo.utils.domain.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @program: springdemo
 * @description 实现日志的增删改查操作的日志留痕
 * @author: Young
 * @create: 2020-05-31 15:02
 **/
@RestController
@RequestMapping("teacher")
@Slf4j
public class TeacherController {

    @Autowired
    private TeacherService teacherService;

    @PostMapping("getAllTeachers")
    @OperateLog(operate = LogOperateType.QUERY,desc = "查询所有教师",userField = "userName",userIndex = 0)
    public Result getAllTeachers(@RequestBody UserBase base) {
        log.info("用户[{}]开始查询所有信息", base.toString());
        List<TeacherEntity> all = teacherService.findAll(base.getUserName());
        log.info("获取到的教师用户有[{}]个", all.size());
        return Result.success(all);
    }
}
